#include				"ASocket.h"

void					ASocket::_getOrderSize()
{
	byte size[2];
	size[0] = _buffer[0];
	size[1] = _buffer[1];
	_current_msg = *((unsigned short*) size);
	if (_current_msg > 4096)
		std::cout << "[CRITICAL] Corrupted packed received" << std::endl;
}

void					ASocket::_handle_write(const boost::system::error_code & ec)
{

}

void					ASocket::setHandler(PacketHandler * handler)
{
	_handler = handler;
}

ASocket::SocketType		ASocket::getSocketType() const
{
	return _type;
}

unsigned int			ASocket::getId() const
{
	return _id;
}

std::vector<byte>		*ASocket::getContent() const
{
	if (_current_msg <= 4096)
	{
		boost::array<byte, 4096>::const_iterator it = _buffer.begin() + this->_current_msg;
		return new std::vector<byte>(_buffer.begin(), it);
	}
	return NULL;
}
